<?php
#基础函数
include_once('_path.php');
include_once("../includes/init.php");
#菜单
$menu = "members";
####变量
#翻页
$page = trim($_GET['page']) + 0; if ($page == "") { $page = $_COOKIE['bmpage']; }
$pagesize = 20;
#搜索
$do = trim($_GET['do']); if ($do == "") { $do = $_COOKIE['bmdo']; }
$word = '';
if ($do == 'search') {
    $word = trim($_GET['word']); if (!isset($_GET['word'])) { $word = $_COOKIE['bmword']; }
}

#!!翻页
if ($page < 1) $page = 1;

#总共数量
$sqlwhere = "WHERE 1 = 1" .iif(strlen($word) > 1, " AND name ='$word'");
$rs_count = $database->queryArray("SELECT count(*) total FROM members_info $sqlwhere");
$total_page = ceil($rs_count[0]["total"] / $pagesize);
if ($total_page < 1) $total_page = 1;
if ($page > $total_page) $page = $total_page;

set_cookie('bmpage', $page, time() + 604800);
set_cookie('bmword', $word, time() + 604800);
set_cookie('bmdo', $do, time() + 604800);

#正式查询
$rsc = $database->queryArray("SELECT * FROM members_info $sqlwhere LIMIT ".(($page - 1) * $pagesize).", $pagesize");
#样式
$css = array();
$js = array("custom");
include_once("../layout/_header.php");
?>
<div class="main">
        <div class="traininc-nav-list">
                        <ul>
                                <li class="selected"><a href="javascript:;">会员列表</a></li>
                                <li><a href="edit.php?action=add.form">新增会员</a></li>

                        </ul>
                </div>
                <div class="box-con">
                <form name="search" action="index.php" method="get">
                    <div class="select-box">姓名查询：<input type="text" name="word" value="<?= htmlspecialchars($word) ?>" size="20">  <input type="submit" name="" value="查询" class="btnA" />
                <input name="do" value="search" type="hidden">
                </div>
                </form>
                <form name="edit" action="update.php" method="post">
                <table id="table1" class="table-blue">
                        <thead>
                                <tr>
                                        <th><input name="aa" class="checkall" type="checkbox"></th>
                                        <th>编号</th>
                                        <th>姓名</th>
                                        <th>手机</th>
                                        <th>网点</th>
                                        <th>卡号</th>
                                        <th>操作</th>
                                </tr>
                        </thead>
                        <tbody>
                                <?
                                for($i=0;$i<sizeof($rsc);$i++){
                                $r = $rsc[$i];
                                $j = 1;
                                ?>
                                <tr <?=iif($j%2==0, 'class="odd"')?>>
                                        <td><input type="checkbox" name="ids[]" value="<?=$r['id']?>"></td>
                                        <td><?=$r['id']?></td>
                                        <td><?=$r['name']?></td>
                                        <td><?=$r['tel']?></td>
                                        <td><?=$r['region']?></td>
                                        <td><?=$r['card']?></td>
                                        <td><a href="edit.php?action=view.form&id=<?= $r['id'] ?>">查看详细</a> | <a href="edit.php?action=delete.do&id=<?= $r['id'] ?>">删除</a></td>
                                </tr>
                                <?
                                $j++;
                                }
                                ?>
                        </tbody>
                </table>
                    <div class="batch-admin"><input class="checkall" type="checkbox"> 全选/反选  <input type="submit" name="" value="删除" class="btnA" /><input type="hidden" name="type" value="delete" /></div>
                </form>
                <div class="digg">
                <? pagination($page, $pagesize, $rs_count[0]["total"], "index.php&page=%s%") ?>
                </div>
                </div>
</div>
<?
include_once("../layout/_footer.php");
?>